package com.glorysoft.xztpda.bindingadapter

import android.text.Editable
import android.text.TextWatcher
import android.widget.EditText
import android.widget.Toast
import androidx.databinding.BindingAdapter
import com.glorysoft.xztpda.entity.ChangeShiftEntity
import com.pda.platform.ui.ui_pdaplatform.utils_public.FreeApi_ToastUtils
import java.lang.NumberFormatException

/**
 * FileName: NumEditextAdapter
 * Author: XJH
 * Date: 2022/4/28 18:34
 * Description:
 * History:
 */
object ShiftLotEditextAdapter {

    @BindingAdapter(value = ["shiftLotEdit"], requireAll = false)
    @JvmStatic
    fun setShiftLotEditText(editText: EditText, item: ChangeShiftEntity) {
        editText.addTextChangedListener(object : TextWatcher {
            override fun beforeTextChanged(s: CharSequence?, start: Int, count: Int, after: Int) {

            }

            override fun onTextChanged(s: CharSequence?, start: Int, before: Int, count: Int) {

            }

            override fun afterTextChanged(s: Editable?) {
                try {
                    val toInt = if (s.toString().isEmpty()) {
                        0
                    } else {
                        s.toString().toInt()
                    }
                    val toInt1 = item.maiN_QTY.toInt()
                    item.remaiN_QTY = (toInt1 - toInt).toString()
                } catch (e: Exception) {
                    item.remaiN_QTY = "0"
                }


            }

        })
    }
}